package cn.bearspark.merit.provider.service.impl;

import cn.bearspark.merit.provider.dao.buffer.AccMeritUserIdZSetBuffer;
import cn.bearspark.merit.provider.dao.mapper.AccMeritMapper;
import cn.bearspark.merit.provider.service.AccMeritService;
import org.springframework.stereotype.Service;

/**
 * @author f
 */
@Service
public class AccMeritServiceImpl implements AccMeritService {

    private final AccMeritMapper accMeritMapper;

    private final AccMeritUserIdZSetBuffer accMeritUserIdZSetBuffer;

    public AccMeritServiceImpl(AccMeritMapper accMeritMapper, AccMeritUserIdZSetBuffer accMeritUserIdZSetBuffer) {
        this.accMeritMapper = accMeritMapper;
        this.accMeritUserIdZSetBuffer = accMeritUserIdZSetBuffer;
    }

    @Override
    public boolean isMerited(long userId, int moduleCode, long moduleDataId) {
        return accMeritUserIdZSetBuffer.exists(userId, moduleCode, moduleDataId);
    }

    @Override
    public void meritArticle(long userId, int moduleCode, long moduleDataId) {
        accMeritMapper.insert(userId, moduleCode, moduleDataId);
    }
}
